﻿using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

class CreateRoomPanel : MonoBehaviour
{
    [SerializeField] TMP_InputField nameIF;
    [SerializeField] TMP_InputField passwordIF;
    [SerializeField] Button exitBT;
    [SerializeField] Button ensureBT;

    private void OnEnable()
    {
        exitBT.onClick.AddListener(OnExit);
        ensureBT.onClick.AddListener(OnEnsure);
    }

    private void OnDisable()
    {
        exitBT.onClick.RemoveListener(OnExit);  
        ensureBT.onClick.RemoveListener (OnEnsure);
    }

    void OnExit()
    {
        gameObject.SetActive(false);
    }

    void OnEnsure()
    {
        ConnectionManager.Instance.StartHost(passwordIF.text, nameIF.text);
        MySceneManager.Instance.LoadSceneByNet("Lobby");                
    }
}